<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
$id=guolv($_GET['id']);
$row=$mysql->query("select * from `article` where `id`='{$id}'");
$rows_type=$mysql->query("select * from `typedata`");
$_pic=str_replace('[weixin]','',$row[0]['pic']);
$row_tp=$mysql->query("select * from `typedata` where `id`='{$row[0]['type']}' limit 1");
if(strpos($row[0]['pic'],"[weixin]")!==0){
	$_pic=$site.$row[0]['pic'];
}
if($_POST){
	//文章编辑
		$title=guolv($_POST['title']);
		$content=guolv($_POST['content']);
		$type=guolv($_POST['type']);
		var_dump($type);
		$pic=guolv($_POST['pic']);
		//过滤sogou图片api
		$content=str_replace('http://img01.store.sogou.com/net/a/04/link?appid=100520031&w=710&url=','',$content);
		$pv_max=guolv($_POST['pv_max']);//浏览次数
		$pv=guolv($_POST['pv']);//浏览次数
		$money=guolv($_POST['money']);//浏览次数
		$aid=guolv($_POST['id']);
		$mysql->execute("update `article` set `title`='{$title}',`pic`='{$pic}',`type`='{$type}',`content`='{$content}',`pv_max`='{$pv_max}',`pv`='{$pv}',`money`='{$money}' where `id`='{$aid}'");
		echo "<script>alert('修改成功');location.href='all_article.php'</script>";
		exit;
}
?>

<?php include('head.php') ?>    
	<link rel="stylesheet" href="../editor/themes/default/default.css" />
	<link rel="stylesheet" href="../editor/plugins/code/prettify.css" />
	<script src="static/jquery.js" type="text/javascript"></script> 
	<script charset="utf-8" src="../editor/kindeditor.js"></script>
	<script charset="utf-8" src="../editor/lang/zh_CN.js"></script>
	<script charset="utf-8" src="../editor/plugins/code/prettify.js"></script>
	<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="content"]', {
				cssPath : '../editor/plugins/code/prettify.css',
				uploadJson : '../editor/php/upload_json.php',
				fileManagerJson : '../editor/php/file_manager_json.php',
				allowFileManager : true,
				filterMode: false,//是否开启过滤模式
			});
			prettyPrint();
		});
	</script>
<script>
			KindEditor.ready(function(K) {
				var uploadbutton = K.uploadbutton({
					button : K('#uploadButton')[0],
					fieldName : 'imgFile',
					url : '../editor/php/upload_json.php?dir=image',
					afterUpload : function(data) {
						if (data.error === 0) {
							var url = K.formatUrl(data.url, 'absolute');
							K('#img').val(url);
                            $.post("../editor/php/dunling.php",{
                            url:url
                            },function(slta,sltb){
                            //****//
                            });
						} else {
							alert(data.message);
						}
					},
					afterError : function(str) {
						alert('自定义错误信息: ' + str);
					}
				});
				uploadbutton.fileBox.change(function(e) {
					uploadbutton.submit();
				});
			});
</script>	
    <div class="container-fluid">
        
        <div class="row-fluid">
		<?php
		include('left.php');
		?>
<div class="span9">
            <h1 class="page-title">文章管理</h1>
<!--			
<div class="btn-toolbar">
    <a href="#myModal" data-toggle="modal" class="btn">Delete</a>
  <div class="btn-group">
  </div>
</div>
-->
<div class="well">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#home" data-toggle="tab">发布</a></li>
      <li><a href="<?php echo $site?>/detail.php?aid=<?php echo $id?>" target="_blank">浏览查看</a></li>
    </ul>
    <div id="myTabContent" class="tab-content">
	<div class="pull-right"><a href="http://img01.store.sogou.com/net/a/04/link?appid=100520031&w=710&url=<?php echo $_pic?>" target="_blank"><img src="http://img01.store.sogou.com/net/a/04/link?appid=100520031&w=710&url=<?php echo $_pic?>" width="150" height="150" border=0></a></div>
      <div class="tab-pane active in" id="home">	  
		<form id="tab" action="edit_article.php" method="post">
		<input type="hidden" name="id" value="<?php echo $id?>">
        <label>标题</label>
        <input type="text" value="<?php echo $row[0]['title']?>" style="width:500px" name="title">
		<label>缩略图</label>
		<input style="width: 250px;" type="text" id="img" value="<?php echo $row[0]['pic']?>" name="pic"/>
		<input type="button" id="uploadButton" class="ke-default-input" value="选择图片"/>
        <label>文章可被阅读总次数(-1，留空，表示无限)</label>
        <input type="text" value="<?php echo $row[0]['pv_max']?>" style="width:200px" name="pv_max"> 
        <label>设置已阅读量</label>
        <input type="text" value="<?php echo $row[0]['pv']?>" style="width:200px" name="pv"> 
        <label>分类</label>
        <select name="type">
        <?php
        	print <<<div
        	<option value="{$row[0]['type']}" selected>{$row_tp[0]['name']}</option>
div;
        	foreach ($rows_type as $row_type) {
        		print <<<div

        	<option value="{$row_type['id']}">{$row_type['name']}-{$row_type['type_pp']}</option>
div;
        	}
        ?>
        </select>
        <?php echo $row_tp['name']?>
		<label>浏览单价：</label>
        <input type="text" value="0.02" style="width:200px" name="money">		
		<textarea value="Smith" rows="10" name="content" style="width:800px;height:400px;visibility:hidden;">
		<?php 
		$html_content=str_replace('http://mmbiz','http://img01.store.sogou.com/net/a/04/link?appid=100520031&w=710&url=http://mmbiz',$row[0]['content']);
		echo $html_content;
		?>
		</textarea>
		 <label></label>
		 <button class="btn btn-primary"><i class="icon-save"></i> 保存</button>
		</form>
      </div>
  </div>
</div>

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Delete Confirmation</h3>
  </div>
  <div class="modal-body">
    
    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
  </div>
</div>

        </div>
    </div>
    

    
    <footer>
        <hr>
        
        <p class="pull-right"><!--power by right--></p>
        
        
        <p><!--power by --></p>
    </footer>
    

    

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="lib/bootstrap/js/bootstrap.js"></script>
  </body>
</html>


